package com.getpebble.android.common.framework.fragment;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import com.getpebble.android.R;
import com.getpebble.android.common.core.trace.Trace;

public class PblListFragment extends PblBaseFragment {
    private final String TAG = PblListFragment.class.getSimpleName();
    private BaseAdapter mAdapter = null;
    private ListView mListView = null;

    public int getLayoutId() {
        return R.layout.fragment_pbl_list;
    }

    public void init(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (container != null) {
            this.mListView = (ListView) container.findViewById(R.id.lv_item_list);
            setAdapter(this.mAdapter);
        }
    }

    public void setAdapter(BaseAdapter adapter) throws IllegalArgumentException {
        this.mAdapter = adapter;
        if (this.mListView != null) {
            this.mListView.setAdapter(adapter);
        }
        if (adapter == null || adapter.getCount() <= 0) {
            showEmptyView();
        } else {
            showFullView();
        }
    }

    public void setOnItemClickListener(OnItemClickListener itemClickListener) {
        if (this.mListView != null) {
            this.mListView.setOnItemClickListener(itemClickListener);
        }
    }

    public void showEmptyView() {
        if (this.mListView != null) {
            this.mListView.setVisibility(8);
        }
    }

    public void showFullView() {
        if (this.mListView != null) {
            this.mListView.setVisibility(0);
        }
    }

    public void setDivider(Drawable drawable) {
        if (this.mListView == null) {
            Trace.warning(this.TAG, "Failed to set divider, view is null");
        } else {
            this.mListView.setDivider(drawable);
        }
    }

    public void setDividerHeight(int height) {
        if (this.mListView == null) {
            Trace.warning(this.TAG, "Failed to set divider height, view is null");
        } else {
            this.mListView.setDividerHeight(height);
        }
    }

    public void setBackgroundColor(int color) {
        if (this.mListView == null) {
            Trace.warning(this.TAG, "Failed to set background color, view is null");
        } else {
            this.mListView.setBackgroundColor(color);
        }
    }

    public void setFastScrollEnabled() {
        if (this.mListView == null) {
            Trace.warning(this.TAG, "Failed to set fast scroll, view is null");
        } else {
            this.mListView.setFastScrollEnabled(true);
        }
    }
}
